@extends('layout')
@section('head')
    @parent
@stop
@section('content')
        <form method="post" action="#">
            <div class="detail_info">
                <input type="text" class="title_hidden" name="title" value="{{$detail['title']}}" readonly>
                @if(Session::get('nickname')=='张某昊')
                    @if($detail['screening']==1)
                        <button type="button" name="delete" class="pro_btn" onclick="offline()">下线</button>
                        @endif
                    <button type="button" name="delete" class="pro_btn" onclick="del()">删除</button>
                    <button type="button" name="ed" class="pro_btn" onclick="edit()">编辑</button>
                @endif
                <button type="button" name="sa" class="pro_btn" onclick="update()" hidden>保存</button>
                <button type="button" name="ca" class="pro_btn" onclick="cancel()" hidden>取消</button>
                <div class="detail_left">
                    <img src="{{$detail['poster']}}"/><br>
                    </div>
                <div class="detail_right">
                    <div>豆辨评分</div>
                    <div class="detail_rating">
                    <div class="detail_score">
                        @if($detail['score']!=null)
                            {{$detail['score']}}
                            @else
                            暂无评分
                            @endif
                    </div>
                    {{--<div class="detail_star">--}}
                    {{--<div>4s</div>--}}
                    {{--<div>1p</div>--}}
                    {{--</div>--}}
                    </div>
                </div>
                <div class="detail_input">
                导演：<input type="text" class="text_hidden" name="director" value="{{$detail['director']}}" readonly><br>
                编剧：<input type="text" class="text_hidden" name="writer" value="{{$detail['writer']}}" readonly><br>
                主演：<input type="text" class="text_hidden" name="actor" value="{{$detail['actor']}}" readonly><br>
                类型：<input type="text" class="text_hidden" name="type" value="{{$detail['type']}}" readonly><br>
                制片国家：<input type="text" class="text_hidden" name="country" value="{{$detail['country']}}" readonly><br>
                语言：<input type="text" class="text_hidden" name="language" value="{{$detail['language']}}" readonly><br>
                上映日期：<input type="text" class="text_hidden" name="date" value="{{$detail['date']}}" readonly><br>
                片长：<input type="text" class="text_hidden" name="time" value="{{$detail['time']}}" readonly><br>
                又名：<input type="text" class="text_hidden" name="alias" value="{{$detail['alias']}}" readonly><br>
                </div>
            </div>
            <div class="detail_introduce">
                <div class="detail_title">
                    {{$detail['title']}}的剧情简介 · · · · · ·
                </div>
            <textarea class="textarea_hidden" style="width: 590px;height: 133px" name="introduce" readonly>{{$detail['introduce']}}</textarea><br><br>
            </div>
        </form>
            <div class="detail_comment">
                <a name="comment"></a>
                <div class="detail_title">
                    {{$detail['title']}}的评论 · · · · · ·({{$num}})
                    <a class="comment_btn" href="javascript:;" onclick="comment()"><span>我要评论</span></a>
                </div>
                <div class="comment_tab">

                    @if(isset($_GET['tag'])&&$_GET['tag']=='new')
                    <a id="hot" href="{{url('detail')}}/{{$detail['id']}}#comment">热门</a>
                    /
                    <a id="new" style="color: black;" href="{{url('detail')}}/{{$detail['id']}}?tag=new#comment">最新</a>
                        @else
                        <a id="hot" style="color: black;" href="{{url('detail')}}/{{$detail['id']}}#comment">热门</a>
                        /
                        <a id="new" href="{{url('detail')}}/{{$detail['id']}}?tag=new#comment">最新</a>
                    @endif
                </div>
                <div class="comment_list">
                    @if($num==0)
                        还没有评论，快来抢沙发
                    @else
                    @foreach($comment as $item)
                    <div class="comment_item">
                        <div class="comment_header">
                            <a href="#">{{$item['user_name']}}</a>
                            <span>
                                @if($item['rating']==10)
                                    <span class="rating_five"></span>
                                @elseif($item['rating']==8)
                                    <span class="rating_four"></span>
                                @elseif($item['rating']==6)
                                    <span class="rating_three"></span>
                                @elseif($item['rating']==4)
                                    <span class="rating_two"></span>
                                @else($item['rating']==2)
                                    <span class="rating_one"></span>
                                @endif
                            </span>
                            <span class="comment_time">{{$item['time']}}</span>
                            @if(Session::get('nickname')=='张某昊')
                                <a href="javascript:;" class="comment_del">删除</a>
                            @elseif(Session::get('nickname')==$item['user_name'])
                                <a href="javascript:;" class="comment_del">删除</a>
                            @endif
                            <span class="comment_assist" style="float: right"><span id="assist{{$item['id']}}" class="comment_num">{{$item['assist_num']}}</span>
                                <a href="javascript:;" id="{{$item['id']}}" class="comment_useful">有用</a>
                            </span>

                        </div>
                        <div class="comment_content">{{$item['content']}}</div>
                    </div>
                        @endforeach
                        @endif
                </div>
                <div class="comment_item"></div>
                @if(isset($_GET['tag'])&&$_GET['tag']=='new')
                {{$comment->appends(array('tag'=>'new'))->links()}}
                    @else
                    {{$comment->links()}}
                    @endif
            </div>
            <div id="hidden" style="display: none">
                <div id="comment_star">
                    <div style="float: left">打个分吧:</div>
                    <div class="star_wrap">
                        <img id="onestar" src="{{URL::asset('assets/img/star_hollow_hover.png')}}">
                        <img id="twostar" src="{{URL::asset('assets/img/star_hollow_hover.png')}}">
                        <img id="threestar" src="{{URL::asset('assets/img/star_hollow_hover.png')}}">
                        <img id="fourstar" src="{{URL::asset('assets/img/star_hollow_hover.png')}}">
                        <img id="fivestar" src="{{URL::asset('assets/img/star_hollow_hover.png')}}">
                    </div>
                    <div id="star_word"></div>
                </div>
                <div id="comment_notice">
                    <span>{{Session::get('nickname')}}，请文明上网理性发言</span>
                    <span id="word_num">500</span>
                </div>
                <div id="comment_input">
                    <textarea id="comment_textarea"></textarea>
                </div>
            </div>
<script>
    function edit() {
        var text=$(".detail_input").children("input");
        text.removeAttr("readonly");
        text.removeClass("text_hidden");
        var textarea=$("textarea");
        textarea.removeAttr("readonly");
        textarea.removeClass("textarea_hidden");
        $("button[name='ca']").show();
        $("button[name='sa']").show();
        $("button[name='ed']").hide();
    }
    function del() {
        dialog({
            title: '提示',
            content: '你确定要删除该影片吗？',
            okValue: '确认',
            ok:function () {
                $.post(
                    "{{url('del_film')}}",
                    {
                        id:"{{$detail['id']}}"
                    },
                    function (data) {
                        if(data=='success'){
                            dialog({
                                title: '提示',
                                content: '操作成功',
                                okValue: '确认',
                                ok:function () {
                                    location.href="{{url('index')}}";
                                },
                            }).show();
                        }
                        else{
                            alert('出错了');
                        }
                    }
                );

            },
            cancelValue: '返回',
            cancel:function () {
            }
        }).show();
    }
    function offline() {
        dialog({
            title: '提示',
            content: '你确定要下线该影片吗？',
            okValue: '确认',
            ok:function () {
                $.post(
                    "{{url('offline')}}",
                    {
                        id:"{{$detail['id']}}"
                    },
                    function (data) {
                        if(data=='success'){
                            dialog({
                                title: '提示',
                                content: '操作成功',
                                okValue: '确认',
                                ok:function () {
                                    location.reload();
                                },
                            }).show();
                        }
                        else{
                            alert('出错了');
                        }
                    }
                );

            },
            cancelValue: '返回',
            cancel:function () {
            }
        }).show();
    }
    function update() {
        $("form").submit();
    }
    function cancel() {
        var text=$(".detail_input").children("input");
        text.attr("class","text_hidden");
        text.attr("readonly","readonly");
        var textarea=$("textarea");
        textarea.attr("class","textarea_hidden");
        textarea.attr("readonly","readonly");
        $("button[name='ca']").hide();
        $("button[name='sa']").hide();
        $("button[name='ed']").show();
    }
    function comment() {
        var username="{{Session::get('nickname')}}";
        if(username==""){
            dialog({
                title: '提示',
                content: '请先登录',
                okValue: '确认',
                ok:function () {
                    location.href="{{url('login')}}";
                },
                cancelValue: '返回',
                cancel:function () {
                }
            }).show();
        }
        else{
        var elem=$("#hidden");
        var d1 = dialog({
            title: '我的评论',
            okValue: '发表',
            ok: function() {
                var word=$('#word_num').text();
                if(word<0){
                    var d3=dialog({
                        content: '你话太多了，大兄弟',
                    }).show();
                    setTimeout(function () {
                       d3.close();
                    },1500);
                    return false;
                }
                else if($('#star_word').text()==""){
                    var d4=dialog({
                        content: '叫你打分！',
                    }).show();
                    setTimeout(function () {
                        d4.close();
                    },1500);
                    return false;
                }
                else{
                    $.post("{{url('send')}}",
                        {
                            rating: $('#star_word').text(),
                            film_id: "{{$detail['id']}}",
                            content: $('#comment_textarea').val(),
                            assist_num: 0,
                            user_name: "{{Session::get('nickname')}}"
                    },function (data) {
                            if(data=="right"){
                                var d2=dialog({
                                    okValue: 'ok',
                                    content: '发表成功',
                                    ok:function () {
                                        location.reload();
                                    }
                                }).show();

                            }
                            else{
                                alert(data);
                            }
                        });
                    return false;
                }
            },
            cancelValue: '取消',
            cancel: function() {}
        });

        d1.content(elem).addEventListener('show', function(){
            var top = $(".ui-popup").offset().top-160;
            $(".ui-popup").css("top",top);
        }).showModal();
     }
    }
    function rate(flag) {
        if(flag==1){
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("简直可怕");
        }
        else if(flag==2){
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("真的难看");
        }
        else if(flag==3){
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("还是可以");
        }
        else if(flag==4){
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("超级好看");
        }
        else if(flag==5){
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fivestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("五星神作");
        }
    }
    $(function () {
        var flag=0;
        //悬停事件
        $("#onestar").hover(function () {
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("简直可怕");
        },function () {
            $("#onestar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#star_word").text("");
            if(flag>0){
                rate(flag);
            }
        });
        $("#twostar").hover(function () {
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("真的难看");
        },function () {
            $("#twostar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#onestar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#star_word").text("");
            if(flag>0){
                rate(flag);
            }
        });
        $("#threestar").hover(function () {
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("还是可以");
        },function () {
            $("#onestar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#twostar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#threestar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#star_word").text("");
            if(flag>0){
                rate(flag);
            }
        });
        $("#fourstar").hover(function () {
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("超级好看");
        },function () {
            $("#onestar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#twostar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#threestar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#fourstar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#star_word").text("");
            if(flag>0){
                rate(flag);
            }
        });
        $("#fivestar").hover(function () {
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fivestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("五星神作");
        },function () {
            $("#onestar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#twostar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#threestar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#fourstar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#fivestar").attr('src', '{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#star_word").text("");
            if(flag>0){
                rate(flag);
            }
        });
        //点击事件
        $("#onestar").click(function () {
            $("#twostar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#fivestar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("简直可怕");
            flag=1;
        });
        $("#twostar").click(function () {
            $("#threestar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#fivestar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("真的难看");
            flag=2;
        });
        $("#threestar").click(function () {
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#fivestar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("还是可以");
            flag=3;
        });
        $("#fourstar").click(function () {
            $("#fivestar").attr('src','{{URL::asset('assets/img/star_hollow_hover.png')}}');
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("超级好看");
            flag=4;
        });
        $("#fivestar").click(function () {
            $("#onestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#twostar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#threestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fourstar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#fivestar").attr('src','{{URL::asset('assets/img/star_onmouseover.png')}}');
            $("#star_word").text("五星神作");
            flag=5;
        });
        //检测字数
        var word=$('#word_num');
        var max=word.text();//可输入字数
        var textarea=$('#comment_textarea');
        textarea.keyup(function () {
            var num=textarea.val().length;//已输入字数
            word.text(max-num);
            if(word.text()<0){
                word.attr('style','color:red');
            }
            else{
                word.attr('style','color:black');
            }
        });

        //点赞
        $(".comment_useful").click(function () {
            var username="{{Session::get('nickname')}}";
            if(username==""){
                dialog({
                    title: '提示',
                    content: '请先登录',
                    okValue: '确认',
                    ok:function () {
                        location.href="{{url('login')}}";
                    },
                    cancelValue: '返回',
                    cancel:function () {
                    }
                }).show();
            }
            else{
            var id=$(this).attr('id');
            $.post("{{url('assist')}}",
                {
                    id:id,
                    assist:"{{Session::get('nickname')}}"
                },
                function (data) {
                    if(data=='right'){
                        var num=parseInt($("#assist"+id).text());
                        num=num+1;
                        $("#assist"+id).text(num);
                    }
                    else{
                        var d=dialog({
                            title:'提示',
                            content:data
                        })
                        d.show();
                        setTimeout(function () {
                            d.close();
                        },1500);
                    }
                });
            }
        });
        var a=$("ul.pagination li a");
        $.each(a,function (i,n) {
           var href=$(this).attr("href");
           $(this).attr("href",href+'#comment');
        });

        //删除评论
        $(".comment_del").click(function () {
            var id=$(this).next().children('a').attr('id');
            dialog({
                title: '提示',
                content: '你确定要删除该条评论吗？',
                okValue: '确认',
                ok:function () {
                    $.post("{{url('del_comment')}}",{
                            id:id
                    },
                        function (data) {
                            if(data=='success'){
                                dialog({
                                    title: '提示',
                                    content: '删除成功',
                                    okValue: '确认',
                                    ok:function () {
                                        location.reload();
                                    },
                                }).show();
                            }
                            else{
                                alert(data);
                            }
                        });
                },
                cancelValue: '返回',
                cancel:function () {
                }
            }).show();
        });
    });

</script>
@stop
@section('sidebar')
    @parent
    @stop